/*

0.0.46

Imebra: a C++ dicom library.
Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008  by Paolo Brandoli

This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 
 as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU AFFERO GENERAL PUBLIC LICENSE Version 3 for more details.

You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE Version 3
 along with this program; If not, see http://www.gnu.org/licenses/

-------------------

If you want to use Imebra commercially then you have to buy the commercial
 license available at http://puntoexe.com
 
After you buy the commercial license then you can use Imebra according
 to the terms described in the Imebra Commercial License Version 1.
A copy of the Imebra Commercial License Version 1 is available in the 
 documentation pages.

Imebra is available at http://puntoexe.com

The author can be contacted by email at paolo@puntoexe.com or by mail at
 the following address:
 Paolo Brandoli
 Preglov trg 6
 1000 Ljubljana
 Slovenia


*/

/*! \file colorTransform.h
    \brief Declaration of the base class used by all the color transforms.

*/


#if !defined(imebraColorTransform_E27C63E7_A907_4899_9BD3_8026AD7D110C__INCLUDED_)
#define imebraColorTransform_E27C63E7_A907_4899_9BD3_8026AD7D110C__INCLUDED_

#include "transform.h"


///////////////////////////////////////////////////////////
//
// Everything is in the namespace puntoexe::imebra
//
///////////////////////////////////////////////////////////
namespace puntoexe
{

namespace imebra
{

namespace transforms
{

/// \namespace puntoexe::imebra::transforms::colorTransforms
/// \brief This namespace contains all the classes
///         involved in the transformation between several
///         color spaces.
///
/// The color transformation is performed on images (see
///  puntoexe::imebra::image).
///
///////////////////////////////////////////////////////////
namespace colorTransforms
{
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
/// \brief This is the base class used by the color
///         transforms classes.
///
/// Each color transform class can handle a color space
///  conversion from one color space to another.
///
/// The class colorTransformsFactory can select the
///  right transform automatically when queried with
///  the initial and the final color spaces as parameters.
///
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
class colorTransform: public transform
{
public:
	// Performs the color transform
	///////////////////////////////////////////////////////////
	virtual void doTransform();

	/// \brief Return the name of the color space that this 
	///         colorTransform can convert.
	///
	/// @return a string with the name of the color space that
	///          can be converted by the colorTransform
	///
	///////////////////////////////////////////////////////////
	virtual std::wstring getInitialColorSpace()=0;

	/// \brief Return the name of the color space that this
	///         colorTransform can generate.
	///
	/// @return a string with the name of the color space that
	///          can be generated by the colorTransform
	///
	///////////////////////////////////////////////////////////
	virtual std::wstring getFinalColorSpace()=0;

	/// \brief Create another instance of the colorTransform
	///         class.
	///
	/// The new instance will have the same type of the 
	///  instance on which this function is called.
	///
	/// @return a new instance of the colorTransform. The new
	///          instance will have the same class of the
	///          instance on which the function is called
	///
	///////////////////////////////////////////////////////////
	virtual ptr<colorTransform> createColorTransform()=0;
	
protected:
	/// \internal
	/// \brief Performs the color conversion.
	///
	/// @param pSourceMem   the buffer of the source image
	/// @param pDestMem     the buffer of the destination image
	/// @param pixelsNumber the number of pixels to be 
	///                      converted
	/// @param inputMinValue the minimum allowed value in the
	///                      pSourceMem buffer
	/// @param inputMaxValue the maximum allowed value in the
	///                      pSourceMem buffer
	/// @param outputMinValue the minimum allowed value in the
	///                      pDestMem buffer
	/// @param outputMaxValue the maximum allowed value in the
	///                      pDestMem buffer
	///
	///////////////////////////////////////////////////////////
	virtual void doColorTransform(imbxInt32* pSourceMem, imbxInt32* pDestMem, imbxUint32 pixelsNumber, imbxInt32 inputMinValue, imbxInt32 inputMaxValue, imbxInt32 outputMinValue, imbxInt32 outputMaxValue)=0;

};


class colorTransformException: public transformException
{
public:
	colorTransformException(const std::string& message): transformException(message){}
};

class colorTransformExceptionWrongColorSpace: public colorTransformException
{
public:
	colorTransformExceptionWrongColorSpace(const std::string& message): colorTransformException(message){}
};

class colorTransformExceptionWrongSize: public colorTransformException
{
public:
	colorTransformExceptionWrongSize(const std::string& message): colorTransformException(message){}
};


///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
/// \internal
/// \brief This class is used by the colorTransform derived
///         classes to register themself.
///
/// Each colorTransform derived class statically allocate
///  a registerColorTransform class that register the
///  color transforms in the colorTransformsFactory.
///
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
class registerColorTransform
{
public:
	/// \brief Register the specified color transform
	///
	/// @param newColorTransform the color transform to be
	///                           registered
	///
	///////////////////////////////////////////////////////////
	registerColorTransform(ptr<colorTransform> newColorTransform);
};

} // namespace colorTransforms

} // namespace transforms

} // namespace imebra

} // namespace puntoexe


#endif // !defined(imebraColorTransform_E27C63E7_A907_4899_9BD3_8026AD7D110C__INCLUDED_)
